<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>

  <body>
    <div id="app">
      <button @click="pushPerson">在数据末尾添加数据</button>
      <button @click="unshiftPerson">在数据开头添加数据</button>
      <button @click="splicePerson">删除数据中间元素</button>
      <ul>
        <li v-for="item of person" :key="item.id">
          {{item.name}}---{{item.age}}
        </li>
      </ul>
    </div>
    <script>
      Vue.config.productionTip = false;

      const vm = new Vue({
        el: "#app",
        data() {
          return {
            person: [
              { id: 1, name: "xiaowang", age: 18 },
              { id: 2, name: "dawang", age: 28 },
              { id: 3, name: "xiaohuang", age: 12 },
              { id: 4, name: "wangzhongwang", age: 30 },
            ],
          };
        },
        methods: {
          pushPerson() {
            this.person.push({
              id: Date.now(),
              name: "zhangsan",
              age: 20,
            });
          },
          unshiftPerson() {
            this.person.unshift({
              id: Date.now(),
              name: "zhaoliu",
              age: 21,
            });
          },
          splicePerson() {
            this.person.splice(3, 1);
          },
        },
      });
    </script>
  </body>
</html>
